// 可以在方法调用前检查用户的权限，决定是否可以调用
let users = {
    '001':{
        roles:['admin']
    },
    '002':{
        roles:['member']
    }
}
function authorize(target,propertyKey,descriptor){
    let old = descriptor.value;
    descriptor.value = function(...args:any[]){
        let user = users[args[0]]
        if(user && user.roles.includes('admin')){
            // old.apply(this,args)
            Reflect.apply(old,this,args)
        }else{
            throw new Error("用户未授权此方法")
        }
    }
}
class AdminPanel{
    @authorize
    deleteUser(userId:string){
        console.log('删除了用户:'+userId);
        
    }
}
const admin = new AdminPanel();
admin.deleteUser('001');
admin.deleteUser('002');